package com.hdd.biz.account.service.impl;

import com.hdd.biz.account.dto.BillRequest;
import com.hdd.biz.account.entity.Account;
import com.hdd.biz.account.entity.AccountBill;
import com.hdd.biz.account.mapper.AccountBillMapper;
import com.hdd.biz.account.mapper.AccountMapper;
import com.hdd.biz.account.service.AccountBillService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hdd.dto.SuperResponse;
import com.hdd.utils.IdUtils;
import com.sun.org.apache.xpath.internal.operations.Number;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.NumberUtils;

import java.math.BigDecimal;

/**
 * <p>
 * 账号 消费账单 服务实现类
 * </p>
 *
 * @author fang
 * @since 2021-02-24
 */
@Service
public class AccountBillServiceImpl extends ServiceImpl<AccountBillMapper, AccountBill> implements AccountBillService {

    @Autowired
    private AccountMapper accountMapper;

    @Override
    public boolean addBill(String accountId, BigDecimal amount, String type, String remarks,String rate,String realityAmount,String chargeAmount ,Integer payType) {
        AccountBill accountBill = new AccountBill();
        accountBill.setBillNo(IdUtils.getNum14());
        accountBill.setAccountId(accountId);
        accountBill.setAmount(amount);
        accountBill.setType(type);
        accountBill.setRemarks(remarks);
        accountBill.setRate(rate);
        accountBill.setPayType(payType);
        accountBill.setRealityAmount(realityAmount);
        accountBill.setChargeAmount(chargeAmount);
       Account account = accountMapper.selectById(accountId);
       if(account!=null){
           accountBill.setBalance(account.getBalance());
       }

        return baseMapper.insert(accountBill)>0?true:false;
    }


    @Override
    public SuperResponse findBillById(BillRequest request) {
        return null;
    }
}
